﻿using System.ComponentModel;
using System.Windows.Forms;
using Medicalsystem.MCP.FormDesigner.Common;
using Medicalsystem.MCP.FormDesigner.Define;
using Medicalsystem.MCP.FormDesigner.Interface;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// 数据查询
    /// </summary>
    [ToolboxItem(false)]
    public partial class MyTimer : UserControl, ICtrlBase
    {
        public MyTimer() { }

        /// <summary>
        /// 按钮控件基类
        /// </summary>
        public MyTimer(Model model) : this(model, EDesignModeState.Run) { }

        public MyTimer(Model model, EDesignModeState designModeState)
        {
            InitializeComponent();

            this.Height = 14;
            _model = model;
            _designModeState = designModeState;
        }

        private EDesignModeState _designModeState = EDesignModeState.Run;
        private Model _model;

        protected GetCtrlProperty _propertyObject = null;
        protected bool _visibleZ = true;

        public string ShowText
        {
            get { return this.label_Name.Text; }
            set
            {
                this.label_Name.Text = value;
                SizeCalculate();
            }
        }

        #region ICtrlBase 成员

        public EDesignModeState DesignModeState
        {
            get
            {
                return _designModeState;
            }
            set
            {
                _designModeState = value;
            }
        }

        public virtual GetCtrlProperty PropertyObject
        {
            get
            {
                if (this._propertyObject == null)
                {
                    this._propertyObject = new GetMyTimerProperty(this);
                }

                return this._propertyObject;
            }
        }

        public virtual EUISizeMode UISizeMode
        {
            get { return EUISizeMode.Null; }
        }

        public Model Model
        {
            get
            {
                return _model;
            }
        }

        #endregion ICtrlBase 成员

        #region IXMLConvertor 成员

        public virtual string ToXML()
        {
            CtrlBasePropertyXML CCPX = new CtrlBasePropertyXML(this);
            return CCPX.ToXML();
        }

        public void FromXML(string strXML)
        {
            if (strXML.Length > 0)
            {
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(string.Format("<MyTimer>{0}</MyTimer>", strXML));

                FromXML(doc.DocumentElement.ChildNodes);
            }
        }

        public virtual void FromXML(System.Xml.XmlNodeList xns)
        {
            if (xns != null && xns.Count > 0)
            {
                CtrlUIPropertyXML CCPX = new CtrlUIPropertyXML(this);

                CCPX.FromXML(xns);
            }
        }

        #endregion IXMLConvertor 成员

        #region ICtrlBase 成员

        public string CtrlID
        {
            get
            {
                return this.Name;
            }
            set
            {
                this.Name = value;
            }
        }

        #endregion ICtrlBase 成员

        private void SizeCalculate()
        {
            this.Width = this.pictureBox1.Width + this.label_Name.Width + 5;
        }
        #region ICtrlBase 成员


        public System.Drawing.Image IcoForToolBox
        {
            get { return Properties.Resources.PropertiesHS; }
        }

        #endregion
    }
}